Vue.filter('money',function(val){
  return '￥'+ (val/100).toFixed(2)
})
let vm = new Vue({
  data(){
    return{
      list:[]
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData(){
      fetch('./data.json').then(data=>data.json()).then(data=>{
        console.log(data)
        this.list = data
      })
    },
    del(item,index){
      // this.list.splice(index,1)
      this.list = this.list.filter(v=>v.id != item.id)
    },
    clear(){
      this.list = []
    }
  },
  computed: {
    checkAll:{
      get(){
        return this.list.every(item=>item.isSelect)
      },
      set(val){
        this.list.forEach(item=>{
          item.isSelect = val
        })
      }
    },
    total(){
      return this.list.reduce((prev,cur)=>{
        return cur.isSelect ?  prev + cur.count * cur.price : prev
      },0)
    }
  }
}).$mount('#app')